    //申请记录页面Url
    __str_apply_url = "https://i.zhaopin.com/schedule?status=viewed";
  
    //已查看记录页面Url
    __str_view_url = "https://i.zhaopin.com/view/resume";
  
    //收藏记录页面Url
    __str_fav_url = "https://i.zhaopin.com/position/collect";

    //职位搜索页面Url
    __str_jobs_url = "https://www.zhaopin.com/sou/";

    //每个页面加载的样式
    __css={
      'apply' :`
            /*申请页面样式调整start */
        
            /*申请页面样式调整end */
      `,
      'view' :`
          /*谁查看我页面样式调整start */


          /*谁查看我页面样式调整end */
          `,
      'fav' :`
            /*收藏页面样式调整start */
    
            /*收藏页面样式调整end */
          `,
      'jobs' :`
          /*职位列表页面样式调整start */


          .positionlist {
            position: relative !important;
          }
   
          .pagination{position:absolute !important;;top:-60px !important;;left:500px !important;;width:550px !important;;height:20px !important;;}

          .pagination__pages {    margin-top: 5px !important;;}
          /*职位列表页面样式调整end */
    `,
}

  // 发送带有参数的消息到后台脚本,获取cookie,start 
  const message = {
    action: "getCookies",
    params: {
      url: "https://liepin.com/"
    }
  };

  chrome.runtime.sendMessage(message, function(response) {
    if (response && response.cookies) {

      var __cookies = {};
      //console.log("Received cookies:", response.cookies);
      response.cookies.forEach(cookie => {
        __cookies[cookie.name] = cookie.value;
      });

      __cookies = __cookies;

    } else {
      console.log("No cookies received.");
    }
  });
    




get_headers = function(page_num){

  return {
    "headers": {
      "accept": "application/json, text/plain, */*",
      "accept-language": "zh-CN,zh;q=0.9",
      "content-type": "application/x-www-form-urlencoded",
      "sec-ch-ua": "\"Google Chrome\";v=\"131\", \"Chromium\";v=\"131\", \"Not_A Brand\";v=\"24\"",
      "sec-ch-ua-mobile": "?0",
      "sec-ch-ua-platform": "\"Windows\"",
      "sec-fetch-dest": "empty",
      "sec-fetch-mode": "cors",
      "sec-fetch-site": "same-site",
      "x-client-type": "web",
      "x-fscp-bi-stat": "{\"location\": \"000000\"}",
      "x-fscp-fe-version": "",
      "x-fscp-std-info": "{\"client_id\": \"0000000\"}",
      "x-fscp-trace-id": "0000000",
      "x-fscp-version": "1.1",
      "x-requested-with": "XMLHttpRequest",
      "x-xsrf-token": "0000000"
    },
    "referrer": "https://c.liepin.com/",
    "body": "curPage="+page_num +"&pageSize=10",
    "method": "POST",
    "mode": "cors",
    "credentials": "include"
  }
}



//#同步申请记录
refresh_apply_info = function(){}

//#同步查看记录
refresh_view_info = function(){}

//#同步收藏记录
refresh_fav_info = function(){}



parse_jobs_info=function(result){
  let arrRstList  = [];

  for(var i=0; i< result.length; i++){
      var item = result[i];
      
      item_info      = {
        job_id: item.number,
        job_name: item.name,
        job_link: item.positionURL,
        company_id: item.companyNumber,
        company_name: item.companyName,
        company_link: item.companyUrl,
        publish_date: DataFormat(new Date(item.firstPublishTime),"yyyy-MM-dd"),
        update_date: DataFormat(new Date(item.publishTime),"yyyy-MM-dd"),
      }

 /*
      {

        "name": "合规风控经理（VCC虚拟卡）",
        "needMajor": [],
        "number": "CCL1484616120J40698930708",
        "orgBestEmployerFlag": 0,
        "orgCommercialTags": [],
        "orgPayedFlag": 0,
        "payload": {
            "name": "",
            "partition": "",
            "score": "",
            "weight": ""
        },
        "positionCommercialLabel": [],
        "positionExpandCardData": "",
        "positionExpandCardType": 0,
        "positionHighlight": "",
        "positionOfNlp": 1,
        "positionSourceType": 1,
        "positionSourceTypeUrl": "",
        "positionURL": "http://jobs.zhaopin.com/CCL1484616120J40698930708.htm",

    
        "companyId": 83924244,
        "companyLogo": "https://rd5-public.zhaopin.cn/imgs/company/1979796464dbb618e296ca1448202c37.jpg",
        "companyName": "上海山美环保装备股份有限公司",
        "companyNumber": "CZ839242440",
        "companyRootId": 83924244,
        "companyScaleTypeTagsNew": [],
        "companySize": "100-299人",
        "companyUrl": "http://company.zhaopin.com/CZ839242440.htm",
        "complainFlag": false,
        "deliveryPath": "",
        "displayPhoneNumber": false,
        "distance": 0,
        "distanceFormat": "",
        "distanceText": "",
        "education": "大专",
        "experimentInfo": null,
        "extensions": null,
        "featureServer": {
            "jdViews3d": "24",
            "lastReplyTime": 1734319168889,
            "lastReplyTimeText": "",
            "reply24h": 28,
            "staffAvgFirstResponseTime7d": 349,
            "staffAvgHandleResumeTime30d": 1274,
            "staffHandleResumeCnts30d": 252,
            "staffReplyRate30d": 0.46,
            "todayReplyNum": 0,
            "todayReplyNumText": ""
        },
        "feedOperation": null,
        "feedPosition": null,
        "financingStage": {
            "code": 1,
            "name": "未融资"
        },
        "firstPublishTime": "2024-04-29 10:08:11",
        "hasAppliedPosition": false,
        "industryCompanyTags": [
            "500020000"
        ],

*/
      arrRstList.push(item_info);
  }

  return arrRstList;
}


//扩展职位搜索页面功能
jobs_page_extend = function(result){

  if(document.location.href.indexOf(__str_jobs_url) < 0 ){
    return;
  }

    //增加全选按钮
    var strHtml = `
    <span style="margin-top: 10px; display: inline-block;">
    只显示近
    <input type="text" id="job_helper_box_pubdate_filter"  value="60">天</span>
    `;
    jQuery(".listsort").append(strHtml);
}




//扩展职位申请,翻页后刷新
jobs_page_extend_refresh_list = function(result){

  if(document.location.href.indexOf(__str_jobs_url) < 0 ){
    return;
  }


  let job_helper_box_pubdate_filter = parseInt(jQuery("#job_helper_box_pubdate_filter").val());
  let today =  timestamp_to_date(Date.now());


  //遍历申请列表，增加申请提示信息
  jQuery(".jobinfo__name").each(function(){

    //职位id，和职位详情页面并不一致，不能从职位详情链接或职位ID
    var str_job_id = jQuery(this).attr("href");
    var job_id =  str_job_id.match(/jobdetail\/([^\/]+)\.htm/)[1];

      var job_info = __arrJobList[job_id];


    if (result){
      if(result[job_id]){
        var strHtml = '<span class="job_helper_box_applyed"  style="height:20px;float:left;">('+result[job_id].publish_date + '发布)</span>';
            jQuery(this).after(strHtml);
            var job_info = __arrJobList[job_id];

          //按日期筛选
          if(dateDiff('d',job_info.publish_date.substring(0,10),today) > job_helper_box_pubdate_filter ){
            jQuery(this).closest(".joblist-box__item").hide();
          }

      }
    }

  });

}



load_local_data = function(){

    jobs_page_extend();

    jQuery("#job_helper_box").remove();
    
}

//ajax调用后的hook
ajax_hook = function(e){

    let url = e.data.url;
    let response = e.data.response;

    console.log(url);

    if(url){

        //判断指定ajax请求,如果实现的是职位搜索列表，等页面渲染完成后，再附加扩展功能需要呈现的功能
        //职位列表
        if(url.indexOf('https://fe-api.zhaopin.com/c/i/search/positions') >= 0 ){

          var jsonRst = {}
          var result  = JSON.parse(response);
              result  = result.data.list;
              result  = parse_jobs_info(result);

              for(var i=0; i< result.length; i++){
                jsonRst[result[i].job_id] = result[i];
              }

              __arrJobList = jsonRst;

            setTimeout(function() {
              jobs_page_extend_refresh_list(jsonRst);
            } ,500);
        }
        

    }

}